package com.appbee.gdata.picasa.client.activity;

import javax.inject.Inject;

import com.appbee.core.client.place.PlaceControl;
import com.appbee.gdata.picasa.client.PicasaActivityModul;
import com.appbee.gdata.picasa.client.place.ThumbnailPlace;
import com.appbee.gdata.picasa.shared.SimpleAlbumProxy;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.view.client.HasData;

public class PicasaAlbumActivity extends AbstractActivity
{
	public interface View extends IsWidget
	{
		public void setActivity(PicasaAlbumActivity activity);
		
		public HasData<SimpleAlbumProxy> getHasData();

		public void clearSelection();
	}
	
	private final View view;
	private final PicasaAlbumDataProvider dataProvider;
	private final PlaceControl placeControl;
	private final PicasaActivityModul activityModul;
	
	@Inject
	public PicasaAlbumActivity(	View view,
								PicasaActivityModul activityModul,
								PicasaAlbumDataProvider dataProvider,
								PlaceControl placeControl)
	{
		super();
		this.view = view;
		this.activityModul = activityModul;
		this.dataProvider = dataProvider;
		this.placeControl = placeControl;
		view.setActivity(this);
	}

	@Override
	public void onStop()
	{
		super.onStop();
		dataProvider.removeDataDisplay(view.getHasData());
	}



	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus)
	{
		dataProvider.addDataDisplay(view.getHasData());
		view.clearSelection();
		panel.setWidget(view);
	}

	public void onAlbumSelected(SimpleAlbumProxy selectedObject)
	{
		placeControl.goTo(new ThumbnailPlace(activityModul
				.getPhotosActivityId(), selectedObject.getId(), 0));
	}

}
